<script lang="ts" setup>
import {ref, onMounted} from "vue";
import api from "@/axios.js";

import router from "@/router/index.js";

defineProps<{
  titleName: String
}>();

onMounted(() => {
  selLoginUserInfo();
})

let userInfo = ref<{
  userName?: String
}>({});

function selLoginUserInfo() {
  api({url: "/selLoginUserInfo"}).then(resp => {
    if (resp.data == "") {
      router.push("/login")
    } else {
      userInfo.value = resp.data;
    }
  });
}

function toLogo() {
  router.push("/index/logo");
}
</script>

<template>
  <div>
    <p class="title" style="cursor: pointer" @click="toLogo">{{ titleName }}</p>
    <p class="userInfo-p">欢迎你，{{ userInfo.userName }}</p>
  </div>
</template>

<style scoped>
.userInfo-p {
  float: left;
  margin-top: 10px;
  margin-left: 70%;
  color: #f6f7ff;
}
</style>